<!doctype html>
<html class="no-js fixed-layout">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>首页</title>
  <meta name="description" content="index">
  <meta name="keywords" content="index">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="/static/assets/i/favicon.png">
  <link rel="apple-touch-icon-precomposed" href="/static/assets/i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="/static/assets/css/amazeui.min.css"/>
  <link rel="stylesheet" href="/static/assets/css/admin.css">
</head>
<body>



  <div class="admin-content">

    <div class="admin-content-body">

      <div class="am-g">


 
        <div class="am-u-sm-12 am-u-md-12 ">
          <!--中间侧块 注意下面是form表-->
          
          <table id="grid" class="am-table am-table-striped am-table-hover table-main am-table-compact am-text-nowrap" width="100%">
            <thead>
              <tr>
                <th class="table-title">角色名称</th>
                <th class="table-title">角色权限</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                  <td style="vertical-align:middle; text-align:center; border: 1px solid #00FFFF"><input id = 'role_id' type="hidden" value="{{ role_id }}">{{ name }}</td>
                  <td style="border: 1px solid #00FFFF">
                      <div id = 'Powermenu1' class="am-u-sm-6">
                        {% for i in data %}
                        <label class="am-checkbox am-success"><input type="checkbox" value="{{ i.menu_id }}" data-am-ucheck> {{ i.menu_name }}</label>
                        {% endfor %}   
                      </div>
                  </td>
              </tr>
            </tbody>
          </table>

          
        </div>
        <div class="am-u-sm-12 am-u-md-6">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
            <div class="am-margin">
              <button type="button" class="am-btn am-btn-primary am-btn-xs" onclick="role_submit({{ role_id }})">保存</button>
            </div>

            </div>
          </div>
        </div>

      </div>
    </div>

  </div>

<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/static/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/static/assets/js/amazeui.min.js"></script>
<script src="/static/assets/js/amazeui.tree.js"></script>
<script src="/static/assets/datatables/amazeui.datatables.min.js"></script>
<script src="/static/assets/dialog/amazeui.dialog.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/assets/css/amazeui.tree.css" />
<script src="/static/assets/js/app.js"></script>
<script type="text/javascript">

  function role_back(){
    window.history.back(-1);
  }
var role_id = {{ nameJS|safe }};
$(document).ready(function(){
      $.ajax({
      "url":"/XTGL_JSGL_4/?role_id="+role_id+"",
      "datatype":"json",
      "type":"get",
      "async":"false"
      }).success(function(data){
        if (data.status == 1) {
          $("#Powermenu1 input").each(function() {
            for(var i=0;i<data.data.length;i++){
              if($(this).val()==data.data[i].menu_id){ 
                $(this).prop('checked',true);
              };
            }
          })
        } else {
          AlertMSG(data.message)
        }
      }).error(function(data){
        AlertMSG("读取权限失败！")
      });
})


function role_submit(role_id){

    var menu_id = "";
    $("#Powermenu1 input").each(function() {
      if ($(this).prop('checked')==true) {
        b = $(this).val();
        menu_id = menu_id + b + '|';
      }
    }); 

    $.ajax({
      "url":"/XTGL_JSGL_5/?role_id="+role_id+"&menu_id="+menu_id+"",
      "datatype":"json",
      "type":"get",
      "async":"false"
      }).success(function(data){
        if (data.status == 1) {
          var index = parent.layer.getFrameIndex(window.name);
          parent.location.reload();
          parent.layer.close(index);
          //window.close();
          //layer.closeAll();
        } else {
          AlertMSG(data.message)
        }
      }).error(function(data){
        AlertMSG("保存失败！")
      });
  
}


var AlertMSG=function(msg){
    AMUI.dialog.alert({ title: '错误提示', content: msg, onConfirm: function() { console.log('close'); } });
}
</script>
</body>

</html>